﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.MediaCenter.UI;

using System.Collections.Specialized;
using System.Net;
using System.IO;
using RadioStream.Code.Utils;


namespace RadioStream
{
    public class CSongInfo : ModelItem
    {
        public CSongInfo()
        {
            m_strArtist = "";
            m_strTitle = "";
            m_strAlbum = "";
            m_strYear = "";
            SetCover("");
            m_iRemainingTime = 0;
        }
        public CSongInfo( String Artist, 
                               String Title, 
                               String Album, 
                               int Year, /*SongNumber*/ 
                               String CoverUrl,
                               int iRemainingTimeSec)
        {
            m_strArtist = Artist;
            m_strTitle = Title;
            m_strAlbum = Album;
            m_strYear = Year.ToString();
            SetCover(CoverUrl);
            m_iRemainingTime = iRemainingTimeSec;
        }

        protected int m_iRemainingTime;
        public int GetRemainingTime
        {
            get
            {
                return m_iRemainingTime;
            }
        }

        protected String m_strCoverUrl;
        protected Microsoft.MediaCenter.UI.Image m_Cover;
        public Microsoft.MediaCenter.UI.Image AlbumCover
        {
            get
            {
                if ("" != m_strCoverUrl)
                    m_Cover = new Microsoft.MediaCenter.UI.Image(m_strCoverUrl);
                else
                    m_Cover = FileUtil.Res2Image("RadioStream.Images.no_cover.jpg");
                return m_Cover;
            }
            set
            { 
                if (m_Cover != value)
                {
                    m_Cover = value;
                    FirePropertyChanged("AlbumCover");
                }
            }

        }

        protected String m_strArtist;
        public String GetArtist()
        {
            string retStr = "Artist unknown";
            if ("" != m_strArtist)
            {
                retStr = m_strArtist;
            }
            return retStr;
        }

        protected String m_strTitle;
        public String GetTitle()
        {
            string retStr = "Title unknown";
            if ("" != m_strTitle)
            {
                retStr = m_strTitle;
            }
            return retStr;
        }

        protected String m_strAlbum;
        public String GetAlbum()
        {
            string retStr = "Album unknown";
            if ("" != m_strAlbum)
            {
                retStr = m_strAlbum;
            }
            return retStr;
        }

        protected String m_strYear;
        public String GetYear()
        {
            string retStr = "Year unknown";
            if ("" != m_strYear)
            {
                retStr = m_strYear;
            }
            return retStr;
        }

        /** Sets the album cover for the song and creates the image for display
         @param strCoverUrl [in] URL of album cover for the song
         */
        public void SetCover(String strCoverUrl)
        {
            m_strCoverUrl = strCoverUrl;
        }
        /** Gets a string representation of the cover URL */
        public String AlbumCoverURL()
        {
            return m_strCoverUrl;
        }


        /*
        private int m_RemainingTimeSeconds;
        public void SetRemainingTimeSeconds(int TimeSeconds)
        {
        }
        public int GetRemainingTimeSeconds()
        {
            return m_RemainingTimeSeconds;
        }
        */

        /*
        private Microsoft.MediaCenter.UI.Text m_strRemainingTimeSeconds;
        public Microsoft.MediaCenter.UI. GetRemainingTime
        {
            get
            {
                return m_Cover;
            }
            set
            {
                if (m_Cover != value)
                {
                    m_Cover = value;
                    FirePropertyChanged("AlbumCover");
                }
            }

        }
        */

        /*
        /// <summary>
        /// Gets the image from URL.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <returns></returns>
        public Image GetImageFromURL(string url)
        {
            HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
            httpWebRequest.Timeout = 10000;
            HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse();
            Stream stream = httpWebReponse.GetResponseStream();
            ImageRequirements Requirements = new ImageRequirements(true);
            return Image.FromStream(stream,Requirements);
        }*/
    }
}
